package com.globalwave.pos.inventory;

import org.junit.Test;

import junit.framework.Assert;

import com.globalwave.pos.inventory.entity.InventoryPeriod;
import static com.globalwave.pos.inventory.entity.InventoryPeriod.*;


public class InventoryPeriodBOTest extends InventoryBaseTestCase {
/*
    @Test
    public void closeAndOpenNext_case1() throws Exception {
    	//Date d20110901000000 = .parse("20110901000000") ;
    	
    	InventoryPeriod inventoryPeriod = getPeriod(201108L) ;
    	Assert.assertEquals("201108 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;

    	inventoryPeriod = getPeriod(201109L) ;
     	Assert.assertEquals("201109 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
     	
     	inventoryPeriod = getPeriod(201110L) ;
     	Assert.assertEquals("201110 - status, ", INVENTORY_PERIOD_STATUS_NOT_OPEN, inventoryPeriod.getStatus_()) ;
     	
     	accessor.begin();
     	getInventoryBO().closeAndOpenNextPeriod(getInventoryBO().currentPeriod()) ;
     	accessor.commit() ;
     	accessor.clear() ; 
     	
     	inventoryPeriod = getPeriod(201108L) ;
    	Assert.assertEquals("after close/open 201108 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201108 - start,  ", dateFormat.parseObject("20110801"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201108 - end,    ", dateFormat.parseObject("20110831"), inventoryPeriod.getEndDate()) ;

    	inventoryPeriod = getPeriod(201109L) ;
     	Assert.assertEquals("after close/open 201109 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201109 - start,  ", dateFormat.parseObject("20110901"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201109 - end,    ", dateFormat.parseObject("20110930"), inventoryPeriod.getEndDate()) ;
     	
     	inventoryPeriod = getPeriod(201110L) ;
     	Assert.assertEquals("after close/open 201110 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201110 - start,  ", dateFormat.parseObject("20111001"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201110 - end,    ", dateFormat.parseObject("20111031"), inventoryPeriod.getEndDate()) ;
    	
    }
    @Test
    public void closeAndOpenNext_case2() throws Exception {
    	//Date d20110901000000 = .parse("20110901000000") ;
    	
    	InventoryPeriod inventoryPeriod = getPeriod(201108L) ;
    	Assert.assertEquals("201108 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;

    	inventoryPeriod = getPeriod(201109L) ;
     	Assert.assertEquals("201109 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
     	
     	inventoryPeriod = getPeriod(201110L) ;
     	Assert.assertNull("201110 - not exist, ", inventoryPeriod) ;
     	
     	accessor.begin();
     	getInventoryBO().closeAndOpenNextPeriod(getInventoryBO().currentPeriod(accessor), accessor) ;
     	
     	accessor.commit() ;
     	accessor.clear() ; 
     	
    	inventoryPeriod = getPeriod(201108L) ;
    	Assert.assertEquals("after close/open 201108 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201108 - start,  ", dateFormat.parseObject("20110801"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201108 - end,    ", dateFormat.parseObject("20110831"), inventoryPeriod.getEndDate()) ;

    	inventoryPeriod = getPeriod(201109L) ;
     	Assert.assertEquals("after close/open 201109 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201109 - start,  ", dateFormat.parseObject("20110901"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201109 - end,    ", dateFormat.parseObject("20110930"), inventoryPeriod.getEndDate()) ;
     	
     	inventoryPeriod = getPeriod(201110L) ;
     	Assert.assertEquals("after close/open 201110 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201110 - start,  ", dateFormat.parseObject("20111001"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201110 - end,    ", dateFormat.parseObject("20111031"), inventoryPeriod.getEndDate()) ;
    	
    }
    

    @Test
    public void closeAndOpenNext_case3() throws Exception {
    	//Date d20111201000000 = .parse("20111201000000") ;
    	
    	InventoryPeriod inventoryPeriod = getPeriod(201111L) ;
    	Assert.assertEquals("201111 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;

    	inventoryPeriod = getPeriod(201112L) ;
     	Assert.assertEquals("201112 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
     	
     	inventoryPeriod = getPeriod(201201L) ;
     	Assert.assertNull("201201 - not exist, ", inventoryPeriod) ;
     	
     	accessor.begin();
     	getInventoryBO().closeAndOpenNextPeriod(getInventoryBO().currentPeriod(accessor), accessor) ;
     	accessor.commit() ;
     	accessor.clear() ; 
     	
     	inventoryPeriod = getPeriod(201111L) ;
    	Assert.assertEquals("after close/open 201111 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201111 - start,  ", dateFormat.parseObject("20111101"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201111 - end,    ", dateFormat.parseObject("20111130"), inventoryPeriod.getEndDate()) ;

    	inventoryPeriod = getPeriod(201112L) ;
     	Assert.assertEquals("after close/open 201112 - status, ", INVENTORY_PERIOD_STATUS_CLOSE, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201112 - start,  ", dateFormat.parseObject("20111201"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201112 - end,    ", dateFormat.parseObject("20111231"), inventoryPeriod.getEndDate()) ;
     	
     	inventoryPeriod = getPeriod(201201L) ;
     	Assert.assertEquals("after close/open 201201 - status, ", INVENTORY_PERIOD_STATUS_OPEN, inventoryPeriod.getStatus_()) ;
    	Assert.assertEquals("after close/open 201201 - start,  ", dateFormat.parseObject("20120101"), inventoryPeriod.getStartDate()) ;
    	Assert.assertEquals("after close/open 201201 - end,    ", dateFormat.parseObject("20120131"), inventoryPeriod.getEndDate()) ;
    	
    }


*/
}
